package zxzx.controller.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 随机信息生成
 * @author 1650085822
 *
 */
public class RandomValue {

	//定义随机选取字段数据
	private static String[] ecoType = "100,110,120,130,140".split(",");
	private static String[] ecoIndusCate = "Q,W,E,R,T,Y,U,I,O,P,A,S,D,F,G,H,J,K,L,Z,X,C,V,B,N,M".split(",");
	private static String[] org = "X1101010000043,X1101010000076".split(",");
	private static String base = "qwertyuiopasdfghjklzxcvbnm0123456789";
	
	/**
	 * 返回随机范围内数值
	 * @param start 
	 * @param end
	 * @return
	 */
	public static int getNum(int start , int end) {
		return (int) (Math.random()*(end-start+1)+start);
	}
	/**
	 * 经济类型代码
	 * @return
	 */
	public static String getEcoType() {
		int index = getNum(0,ecoType.length-1);
		String first = ecoType[index];
		return first;
	}
	/**
	 * 行业分类代码
	 * @return
	 */
	public static String getEcoIndusCate() {
		int index = getNum(0, ecoIndusCate.length-1);
		String first = ecoIndusCate[index];
		return first;
	}
	
	/**
	 * 数据提供机构段码
	 * @return
	 */
	public static String getOrg() {
		int index = getNum(0, org.length-1);
		String first = org[index];
		return first;
	}
	/**
	 * 按格式获取时间s
	 * @param date
	 * @return
	 */
	public static String strToDateFormat(String date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
		dateFormat.setLenient(false);
		Date newDate = null;
		try {
			newDate = dateFormat.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		return dateFormat.format(newDate);
	}
	
		/**
		 * 按照传入长格式字符串进行截取
		 * @param date
		 * @return
		 */
		public static String strToCdateFormat(String date) {
			String value = "";
			if(date.length() >= 18) {
				value = date.substring(6, 14);
			}
			return value;
		}
}
